package com.icodingedu.springcloud.service;

import com.icodingedu.springcloud.pojo.PortInfo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class RequestCacheService {

    @Resource
    private MyService myService;

    //这里就是将结果缓存并根据参数来进行K-V的缓存对应
    @CacheResult
    @HystrixCommand(commandKey = "cacheKey")
    public PortInfo requestCache(@CacheKey String name){
        log.info("request cache name "+name);
        PortInfo portInfo = new PortInfo();
        portInfo.setPort("2020");
        portInfo.setName(name);
        portInfo = myService.sayHello(portInfo);
        return portInfo;
    }
}
